/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui.manageplugins;


import java.awt.Component;
import java.util.Vector;
import javax.swing.JProgressBar;
import javax.swing.table.TableCellRenderer;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableColumnModel;

public class MyProgressCell extends JProgressBar implements TableCellRenderer{

  static final long serialVersionUID=4376898900l;
  public int k=0;

  Vector<Integer> values = new Vector<Integer>();
  private JTable table;

  public MyProgressCell(JTable table, int col)
  {
	   super();
	   setMaximum(100);
	   setMinimum(0);
	   setStringPainted(true);

       TableColumnModel columnModel = table.getColumnModel();
        columnModel.getColumn(col).setCellRenderer(this);
        this.table = table;
	}

  public int incr(int val)
  {
      setValue(k+val);
	  return getValue();
  }

  public int addRow(){
      values.add(0);
      return values.size()-1;
  }

  public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected, boolean hasFocus,
            int row, int column) {
        if (hasFocus) {
            this.setForeground(table.getForeground());
            this.setBackground(UIManager.getColor(
                    "Button.background"));
        } else if (isSelected) {
            this.setForeground(table.getSelectionForeground());
            this.setBackground(table.getSelectionBackground());
        } else {
            this.setForeground(table.getForeground());
            this.setBackground(UIManager.getColor(
                    "Button.background"));
        }
        //   value = "Borrar";
        this.setString((value == null) ? "" : value.toString());
        //System.out.println("MyProgreessCell size value:"+values.size());
        setValue(values.get(row));
        return this;
    }

  public void setValueAt(int value, int row){
      if(values.size()-1<row){
          addRow();
      }
      //System.out.println(values.size()+" "+row+" value "+value);
      values.removeElementAt(row);
      values.insertElementAt(value, row);
      //this.table.repaint();
  }

  public void removeRowValue(int row){
      values.removeElementAt(row);
      this.table.repaint();
  }

}
